package JavaDowork.pratice6;

public class Q7 {

    public static void main(String[] args) {
        printPascalTriangle(10);
    }

    static void printPascalTriangle(int rows) {
        for (int i = 0; i < rows; i++) {
            // 打印每一行
            for (int j = 0; j <= i; j++) {
                // 计算第i行第j个元素的值
                int value = calculatePascalTriangleValue(i, j);
                System.out.print(value + " ");
            }
            System.out.println();
        }
    }

    static int calculatePascalTriangleValue(int row, int col) {
        if (col == 0 || col == row) {
            return 1;
        } else {
            return calculatePascalTriangleValue(row - 1, col - 1) + calculatePascalTriangleValue(row - 1, col);
        }
    }
}
